import moment from "moment";






/**
 * 计算上次时间
 */
function calLastTime(val: any) {
    moment.suppressDeprecationWarnings = true;
    val = moment(val).format("YYYY-MM-DD HH:mm:ss");
    const now = moment().format("YYYY-MM-DD HH:mm:ss");
    const seconds = moment(now).diff(val, "seconds");
    if (seconds <= 60) {
        return seconds + "秒前";
    } else if (seconds <= 3600) {
        return (seconds / 60).toFixed(0) + "分钟前";
    } else if (seconds <= 86400) {
        return (seconds / 3600).toFixed(0) + "小时前";
    } else if (seconds <= 2592000) {
        return moment(now).diff(val, "days") + "天前";
    } else if (seconds <= 31104000) {
        return moment(now).diff(val, "months") + "月前";
    } else {
        return moment(now).diff(val, "years") + "年前";
    }
}


const replaceStr = (str: string, index: any, char: any) => {
    return str.substring(0, index) + char + str.substring(index + 1);
}

export default {
    calLastTime,
	moment,
	replaceStr,
}